<?php

namespace app\common\model\xiaohongshu;

use think\Model;


class Black extends Model
{

    

    

    // 表名
    protected $name = 'xiaohongshu_black';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'verify_data_text',
        'reason_images_urls'
    ];
    

    
    public function getStatusList()
    {
        return ['0' => '未审核', '1' => '审核通过', '2' => '审核拒绝'];
    }

    public function getVerifyDataList()
    {
        return ['0' => __('Verify_data 0'), '1' => __('Verify_data 1'), '2' => __('Verify_data 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getVerifyDataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['verify_data']) ? $data['verify_data'] : '');
        $list = $this->getVerifyDataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function author(){
        return $this->belongsTo(Author::class,'uuid','uuid');
    }

    public function type()
    {
        return $this->belongsTo(Type::class, 'xiaohongshu_type_id', 'id');
    }

    public function getXiaohongshuTypeNameAttr($value, $data)
    {
        return $this->type ? $this->type->name : '未知类型';
    }

    public function getReasonImagesUrlsAttr($value, $data)
    {
        $domain = request()->domain();
        $images = explode(',', $data['reason_images']);
        return array_map(function ($image) use ($domain) {
            return $domain . '/' . ltrim($image, '/');
        }, $images);
    }



}
